from core.basehandler import BaseHandler
from core.room import Room
from core.action import Action
from core.support import get_game
from items.knife import Knife
from items.inner_tube import InnerTube

class StartingPoint(Room):
    
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room
        self.signal_fire_created = False
        
        # build list of actions
        self.add_action(In)
        self.add_action(ToBeach1)
        self.add_action(ToBeach2)
        self.add_item(InnerTube())
        self.add_item(Knife())
    
    # return description of room.
    def get_description(self):
        return '''
        You wash up on the shore of a beach. There is more beach to your left and right and a path into the forest straight ahead.
        '''
    # return image of room
    def get_image(self):
        if self.signal_fire_created:
            return 'signal_fire.jpg'
        else:
            return 'startingpoint.jpg'
         

class StartingPointHandler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return StartingPoint

# define actions for this room

class In(Action):
    def __init__(self):
        Action.__init__(self, "In")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Go into the forest"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        game = get_game()
        player = game.get_player()
        if player.death_count > 0:
            return 'forest'
        else:
            return 'death'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"

    # this method gets called when action executed.  can be overridden in subclass
    def do_action(self,game,room,request):
        player = game.get_player()
        player.death_count -= 1
        return
    
class ToBeach1(Action):
    def __init__(self):
        Action.__init__(self, "ToBeach1")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Go left"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        game = get_game()
        player = game.get_player()
        if player.death_count > 0:
            return 'beach1'
        else:
            return 'death'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
    # this method gets called when action executed.  can be overridden in subclass
    def do_action(self,game,room,request):
        player = game.get_player()
        player.death_count -= 1
        return

class ToBeach2(Action):
    def __init__(self):
        Action.__init__(self, "ToBeach2")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Go right"
    
    # return id of room to enter when action is complete
    def get_destination(self):
        game = get_game()
        player = game.get_player()
        if player.death_count > 0:
            return 'beach2'
        else:
            return 'death'
    
    # return http method to use when user clicks on this action
    # use "get" if just moving to another room.  if changing something
    # like the state of an inventory item or room then use "post"
    def get_method(self):
        return "get"
    
    # this method gets called when action executed.  can be overridden in subclass
    def do_action(self,game,room,request):
        player = game.get_player()
        player.death_count -= 1
        return